package com.mic.yzzn.plc.common.control.datastructure;

import java.io.Serializable;

/**
 * 用于表示 Collector 内部指令队列的状态的类
 */
public class PLCCollectorQueueStatus implements Serializable
{

	/** 采集器ID: IP-PORT-LOCATION */
	private String collectorID = "null";
	/** 当前执行到的指令数字索引 -1:不适用 */
	private int indexOfCurrentIns = 0;
	/** 未执行的指令数目 */
	private int numberOfRemainIns = 0;
	/** 已经执行的指令数目 */
	private int numberOfFinishIns = 0;
	/** 事件对应的队列优先级 {0: 实时写入队列 1: 实时读取队列 2: 周期任务队列} */
	private int instructionPriority = 0;

	/** 序列化ID */
	private static final long serialVersionUID = -7368763624764153628L;
	
	// 初始化
	public PLCCollectorQueueStatus()
	{
		
	}
	
	public PLCCollectorQueueStatus(String collectorID, int indexOfCurrentIns, int numberOfRemainIns, int numberOfFinishIns, int instructionPriority)
	{
		this.collectorID = collectorID;
		this.indexOfCurrentIns = indexOfCurrentIns;
		this.numberOfRemainIns = numberOfRemainIns;
		this.numberOfFinishIns = numberOfFinishIns;
		this.instructionPriority = instructionPriority;
	}

	@Override
	public String toString()
	{
		StringBuffer buffer = new StringBuffer();
		buffer.append("采集器ID: " + collectorID + '\n');
		buffer.append("当前执行到的位置: " + indexOfCurrentIns + ", ");
		buffer.append("剩余指令数目: " + numberOfRemainIns + ", ");
		buffer.append("已经执行的指令数目: " + numberOfFinishIns + ", ");
		buffer.append("队列优先级: " + instructionPriority);

		return buffer.toString();
	}

	// Getter
	
	public String getCollectorID()
	{
		return collectorID;
	}
	
	public int getIndexOfCurrentIns()
	{
	    if (instructionPriority!= PLCMission.PLCMISSION_PRIORITY_CYR_2)
	    {
	    	return -1;
	    }
	    
		return indexOfCurrentIns;
	}
	
	public int getNumberOfFinishIns()
	{
		return numberOfFinishIns;
	}
	
	public int getNumberOfRemainIns()
	{
		return numberOfRemainIns;
	}
	
	public int getInstructionPriority()
	{
		return instructionPriority;
	}
	
	// Setter
	
	public void setCollectorID(String collectorID)
	{
		this.collectorID = collectorID;
	}
	
	public void setIndexOfCurrentIns(int indexOfCurrentIns)
	{
		this.indexOfCurrentIns = indexOfCurrentIns;
	}
	
	public void setInstructionPriority(int instructionPriority)
	{
		this.instructionPriority = instructionPriority;
	}
	
	public void setNumberOfFinishIns(int numberOfFinishIns)
	{
		this.numberOfFinishIns = numberOfFinishIns;
	}
	
	public void setNumberOfRemainIns(int numberOfRemainIns)
	{
		this.numberOfRemainIns = numberOfRemainIns;
	}
}
